package com.party.core.service.mall.impl;

import com.google.common.base.Strings;
import com.party.common.paging.Page;
import com.party.common.utils.UUIDUtils;
import com.party.core.dao.read.mall.MallGoodsFavoriteReadDao;
import com.party.core.dao.write.mall.MallGoodsFavoriteWriteDao;
import com.party.core.model.mall.MallGoodsFavorite;
import com.party.core.service.mall.IMallGoodsFavoriteService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Set;

/**
 * 商品收藏
 * Created by yifeng
 *
 * @date 2018/4/27 0027
 * @time 下午 18:55
 */
@Service
public class MallGoodsFavoriteService implements IMallGoodsFavoriteService {
    @Autowired
    private MallGoodsFavoriteReadDao mallGoodsFavoriteReadDao;
    @Autowired
    private MallGoodsFavoriteWriteDao mallGoodsFavoriteWriteDao;


    @Override
    public String insert(MallGoodsFavorite mallGoodsFavorite) {
        mallGoodsFavorite.setId(UUIDUtils.generateRandomUUID());
        mallGoodsFavorite.setUpdateDate(new Date());
        boolean result = mallGoodsFavoriteWriteDao.insert(mallGoodsFavorite);
        if (result) {
            return mallGoodsFavorite.getId();
        }
        return null;
    }

    @Override
    public boolean update(MallGoodsFavorite mallGoodsFavorite) {
        return mallGoodsFavoriteWriteDao.update(mallGoodsFavorite);
    }

    @Override
    public boolean deleteLogic(String id) {
        return false;
    }

    @Override
    public boolean delete(String id) {
        if (Strings.isNullOrEmpty(id)) {
            return false;
        }
        return mallGoodsFavoriteWriteDao.delete(id);
    }

    @Override
    public boolean batchDeleteLogic(Set<String> ids) {
        return false;
    }

    @Override
    public boolean batchDelete(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return false;
        }
        return mallGoodsFavoriteWriteDao.batchDelete(ids);
    }

    @Override
    public MallGoodsFavorite get(String id) {
        return mallGoodsFavoriteReadDao.get(id);
    }

    @Override
    public List<MallGoodsFavorite> listPage(MallGoodsFavorite mallGoodsFavorite, Page page) {
        return mallGoodsFavoriteReadDao.listPage(mallGoodsFavorite, page);
    }

    @Override
    public List<MallGoodsFavorite> list(MallGoodsFavorite mallGoodsFavorite) {
        return mallGoodsFavoriteReadDao.listPage(mallGoodsFavorite, null);
    }

    @Override
    public List<MallGoodsFavorite> batchList(Set<String> ids, MallGoodsFavorite mallGoodsFavorite, Page page) {
        return null;
    }

    @Override
    public MallGoodsFavorite getUnique(MallGoodsFavorite mallGoodsFavorite) {
        return mallGoodsFavoriteReadDao.getUnique(mallGoodsFavorite);
    }

    @Override
    public Long findByGoodsId(String goodsId) {
        return mallGoodsFavoriteReadDao.findByGoodsId(goodsId);
    }

    @Override
    public void deleteByGoods(String goodsId) {
        mallGoodsFavoriteWriteDao.deleteByGoods(goodsId);
    }
}
